import React, { useState, useEffect } from 'react'
import { Cell, Rate, Toast, Input, Button, Uploader, Radio } from 'react-vant'
import { useNavigate, useLocation } from 'react-router-dom'
export default function Fabupl() {
    let navigate = useNavigate()
    let location = useLocation()
    console.log(location);
    let [data, setData] = useState(location.state.i)
    let [ping, setPing] = useState({
        xing: '',
        pj: "",
        img: [],
        ni: '',
    })
    let ti = async (obj) => {
        console.log(obj);
        if (ping.xing == '' || ping.pj == '') {
            Toast.fail('请填写完整信息')
        } else {
            obj.status = true
            obj.ping = ping

            // let { data } = await axios.post('http://localhost:3000/pingjia1', obj)
            Toast.success('提交成功')
            navigate('/pingjia')
        }
    }
    return (
        <div>
            <div>
                <Cell
                    center
                    title={`演出评分`}
                    label='满意请打五星哦'
                >
                    <Rate value={ping.xing} onChange={(e) => { setPing({ ...ping, xing: e }) }} color='yellow' />
                </Cell>
                <Cell style={{ marginTop: 10 }}>
                    <Input.TextArea
                        value={ping.pj}
                        onChange={(e) => { setPing({ ...ping, pj: e }) }}
                        autoSize={{ minHeight: 130, maxHeight: 120 }}
                        placeholder="您的评价会帮助到更多的人哦" maxLength={500} showWordLimit />
                </Cell>
                <Cell style={{ marginTop: 10 }}>
                    <Uploader
                        accept='*'
                        onChange={v => setPing({ ...ping, img: v })}
                    />
                </Cell>
                <Radio.Group>
                    <Radio name="1" onClick={() => { setPing({ ...ping, ni: '匿名' }) }}>匿名评价</Radio>
                </Radio.Group>
                <Button type='danger' size='large' style={{ position: 'fixed', bottom: '10px' }}
                    onClick={() => { ti(data) }}>
                    提交
                </Button>
            </div>
        </div>
    )
}
